package com.zy.mc_module.wheel.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.zy.mc_module.R;

/**
 * Created on 19/2/27
 * 加载框
 */
public class LoadingDialog extends Dialog {
    private String title;
    private boolean flag = true;

    public LoadingDialog(@NonNull Context context) {
        super(context, R.style.LoadingDialog);
        this.title = "请稍后...";
    }

    public LoadingDialog(@NonNull Context context, boolean flag) {
        super(context, R.style.LoadingDialog);
        this.title = "请稍后...";
        this.flag = flag;
    }

    public LoadingDialog(@NonNull Context context, String title) {
        super(context, R.style.LoadingDialog);
        this.title = title;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_loading);
        setCanceledOnTouchOutside(false);
        setCancelable(flag);
        initView();
    }

    private void initView() {
        TextView tv_title = findViewById(R.id.loading_title);
        tv_title.setText(title);
    }

    @Override
    public void dismiss() {
        try {
            if (null != this && this.isShowing()) {
                super.dismiss();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

